/*
 * @Author       : xiangmin
 * @File         : 树状数据根据关键字过滤
 * @Date         : 2023-10-24 16:31:26
 * @LastEditors  : xiangmin
 * @LastEditTime : 2023-10-24 16:46:45
 */
export function filterTree(tree, keyword) {
	return tree.reduce((filtered, node) => {
		const newNode = { ...node }
		if (newNode.children) {
			newNode.children = filterTree(newNode.children, keyword)
		}

		if (newNode.title.includes(keyword) || (newNode.children && newNode.children.length > 0)) {
			filtered.push(newNode)
		}
		return filtered
	}, [])
}
